using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JSON;

public class JSONScene{
	#region 单例
	private static JSONScene instance;
	public static JSONScene getInstance(){
	if (instance == null)
		instance = new JSONScene ();
		return instance;
	}
	#endregion

	#region 变量
	private JSONNode json;
	private JSONNode JSONData{
		get{
			if(json == null)
				json = JsonRead.Read("JSONScene");
			return json;
		}
	}
	#endregion
	#region 外部调用
	public void Clear(){
		json = null;
	}
	public JSONNode GetJSON(string key){
		return JSONData [key];
	}
	public JSONNode GetJSON(int index){
		return JSONData [index];
	}
	/// <summary>
	/// 有多少个数据
	/// </summary>
	public int GetCount(){
	return JSONData.Count;
	}

    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListID(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetID(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 副本id
	/// </summary>
	public int GetID(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["ID"].AsInt;
		return  value;
	}
	/// <summary>
	/// 副本id :From Index
	/// </summary>
	public int GetID(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetID(index.ToString());
			return  value;
		}
		value = json["ID"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListGameTime(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetGameTime(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 限制时间
	/// </summary>
	public int GetGameTime(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["GameTime"].AsInt;
		return  value;
	}
	/// <summary>
	/// 限制时间 :From Index
	/// </summary>
	public int GetGameTime(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetGameTime(index.ToString());
			return  value;
		}
		value = json["GameTime"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListRank(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetRank(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 阶级
	/// </summary>
	public int GetRank(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Rank"].AsInt;
		return  value;
	}
	/// <summary>
	/// 阶级 :From Index
	/// </summary>
	public int GetRank(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetRank(index.ToString());
			return  value;
		}
		value = json["Rank"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListMonsterGroup(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetMonsterGroup(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 召唤怪物组 (jsno[[id,num]]) 
	/// </summary>
	public string GetMonsterGroup(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["MonsterGroup"].ToString();
		return  value;
	}
	/// <summary>
	/// 召唤怪物组 (jsno[[id,num]])  :From Index
	/// </summary>
	public string GetMonsterGroup(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetMonsterGroup(index.ToString());
			return  value;
		}
		value = json["MonsterGroup"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListMonsterPortal(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetMonsterPortal(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 召唤门1刷新时间 ([门1时间,门2时间，1，2···]) 
	/// </summary>
	public string GetMonsterPortal(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["MonsterPortal"].ToString();
		return  value;
	}
	/// <summary>
	/// 召唤门1刷新时间 ([门1时间,门2时间，1，2···])  :From Index
	/// </summary>
	public string GetMonsterPortal(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetMonsterPortal(index.ToString());
			return  value;
		}
		value = json["MonsterPortal"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListGuard(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetGuard(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// boss守卫 (怪物表映射ID) 
	/// </summary>
	public int GetGuard(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Guard"].AsInt;
		return  value;
	}
	/// <summary>
	/// boss守卫 (怪物表映射ID)  :From Index
	/// </summary>
	public int GetGuard(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetGuard(index.ToString());
			return  value;
		}
		value = json["Guard"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListBoss(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetBoss(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 最终boss (怪物表映射ID) 
	/// </summary>
	public int GetBoss(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Boss"].AsInt;
		return  value;
	}
	/// <summary>
	/// 最终boss (怪物表映射ID)  :From Index
	/// </summary>
	public int GetBoss(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetBoss(index.ToString());
			return  value;
		}
		value = json["Boss"].AsInt;
		return  value;
	}

	#endregion
}